﻿using System;
using System.Linq;
using ConsoleTables;
using IceCS.SqlSugar.Cmd.Models;

namespace IceCS.SqlSugar.Cmd
{
    class Program
    {
        static void Main(string[] args)
        {
            AppDbContext.CreateTables();
            InsertData();
            //QueryData();
        }

        static void InsertData()
        {
            AppDbContext.UseSqlSugarClient(client =>
            {
                client.Insertable(new Schools()
                {
                    SchoolId = 5545,
                    SchoolName = "云山区第一小学"
                });

                foreach (var id in Enumerable.Range(1, 10))
                {
                    client.Insertable(new Students()
                    {
                        Id = id,
                        Age = 15,
                        ClassName = "高二一班",
                        SchoolId = 5545,
                        StudentName = "张三 " + id,
                        Time = DateTime.Now
                    });
                }

            });
            AppDbContext.School.Insert(new Schools()
            {
                SchoolId = 5546,
                SchoolName = "云山区第二小学"
            });
        }

        static void QueryData()
        {
            AppDbContext.UseSqlSugarClient(client =>
            {
                var result1 = client.Queryable<Schools>().ToList();
                var table = ConsoleTable.From(result1);
                table.Write();
            });
        }
    }
}
